<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>LiftSimu: /Users/alrik/Documents/workspace/LiftSimu/src/JShaftPanel.java Quellcode</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="up.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">LiftSimu
   
   </div>
   <div id="projectbrief">die Simulation einer Liftanlage</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Erzeugt von Doxygen 1.8.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Suchen');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Hauptseite</span></a></li>
      <li><a href="annotated.html"><span>Klassen</span></a></li>
      <li class="current"><a href="files.html"><span>Dateien</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Suchen" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>Auflistung&#160;der&#160;Dateien</span></a></li>
    </ul>
  </div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>Alle</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Klassen</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Dateien</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Funktionen</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variablen</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">/Users/alrik/Documents/workspace/LiftSimu/src/JShaftPanel.java</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_j_shaft_panel_8java.html">gehe zur Dokumentation dieser Datei</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="keyword">import</span> java.awt.*;
<a name="l00002"></a>00002 <span class="keyword">import</span> java.awt.event.ComponentEvent;
<a name="l00003"></a>00003 <span class="keyword">import</span> java.awt.event.ComponentListener;
<a name="l00004"></a>00004 <span class="keyword">import</span> java.awt.geom.Rectangle2D;
<a name="l00005"></a>00005 
<a name="l00006"></a>00006 <span class="keyword">import</span> javax.swing.*;
<a name="l00007"></a>00007 
<a name="l00027"></a>00027 @SuppressWarnings(<span class="stringliteral">&quot;serial&quot;</span>)
<a name="l00028"></a><a class="code" href="class_j_shaft_panel.html">00028</a> public class <a class="code" href="class_j_shaft_panel.html" title="Das Panel, auf dem der Fahrstuhlschacht gezeichnet wird.">JShaftPanel</a> extends JPanel {
<a name="l00029"></a><a class="code" href="class_j_shaft_panel.html#a798a3e958aba9fc6dd074ff266088626">00029</a>    <span class="keyword">private</span> <span class="keywordtype">int</span> doorcond, floordoor, liftpos, <a class="code" href="class_j_shaft_panel.html#a798a3e958aba9fc6dd074ff266088626">personenanz</a>;
<a name="l00030"></a><a class="code" href="class_j_shaft_panel.html#a20200caea28309543d1188c64b4fda3e">00030</a>    Image <a class="code" href="class_j_shaft_panel.html#a20200caea28309543d1188c64b4fda3e">offscreenImage</a>;
<a name="l00031"></a><a class="code" href="class_j_shaft_panel.html#a132e1ef3edf83694226af329c04648cc">00031</a>    Graphics <a class="code" href="class_j_shaft_panel.html#a132e1ef3edf83694226af329c04648cc">offscreenGraphics</a>;
<a name="l00032"></a><a class="code" href="class_j_shaft_panel.html#a603b3d01883db039085ad1bd4a9ada62">00032</a>    Image images[], currentimage;
<a name="l00033"></a>00033    
<a name="l00039"></a><a class="code" href="class_j_shaft_panel.html#aa97b2a2a7ca418e3279c550e108479b8">00039</a>    <span class="keyword">public</span> <a class="code" href="class_j_shaft_panel.html#aa97b2a2a7ca418e3279c550e108479b8" title="Der Konstruktor.">JShaftPanel</a>(){
<a name="l00040"></a>00040       super();
<a name="l00041"></a>00041       personenanz=0;
<a name="l00042"></a>00042       drawDoors(0,1);
<a name="l00043"></a>00043       images = <span class="keyword">new</span> Image[15];
<a name="l00044"></a>00044       <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i&lt;15;i++){
<a name="l00045"></a>00045          
<a name="l00046"></a>00046          images[i] = Toolkit.getDefaultToolkit().getImage(getClass().getResource(<span class="stringliteral">&quot;images/&quot;</span>+Integer.toString(i)+<span class="stringliteral">&quot;.jpg&quot;</span>));
<a name="l00047"></a>00047          
<a name="l00048"></a>00048          <span class="comment">//images[i] = new ImageIcon(&quot;images/&quot;+Integer.toString(i)+&quot;.jpg&quot;).getImage();</span>
<a name="l00049"></a>00049       }
<a name="l00050"></a>00050       
<a name="l00051"></a>00051       addComponentListener(<span class="keyword">new</span> ComponentListener() 
<a name="l00052"></a>00052         {  
<a name="l00053"></a>00053                 <span class="keyword">public</span> <span class="keywordtype">void</span> componentResized(ComponentEvent evt) {
<a name="l00054"></a>00054                  changePicture();
<a name="l00055"></a>00055                 }
<a name="l00056"></a>00056 
<a name="l00057"></a>00057             @Override
<a name="l00058"></a>00058             <span class="keyword">public</span> <span class="keywordtype">void</span> componentHidden(ComponentEvent arg0) {
<a name="l00059"></a>00059                <span class="comment">// TODO Auto-generated method stub</span>
<a name="l00060"></a>00060                
<a name="l00061"></a>00061             }
<a name="l00062"></a>00062 
<a name="l00063"></a>00063             @Override
<a name="l00064"></a>00064             <span class="keyword">public</span> <span class="keywordtype">void</span> componentMoved(ComponentEvent arg0) {
<a name="l00065"></a>00065                <span class="comment">// TODO Auto-generated method stub</span>
<a name="l00066"></a>00066                
<a name="l00067"></a>00067             }
<a name="l00068"></a>00068 
<a name="l00069"></a>00069             @Override
<a name="l00070"></a>00070             <span class="keyword">public</span> <span class="keywordtype">void</span> componentShown(ComponentEvent arg0) {
<a name="l00071"></a>00071                <span class="comment">// TODO Auto-generated method stub</span>
<a name="l00072"></a>00072                
<a name="l00073"></a>00073             }
<a name="l00074"></a>00074         });
<a name="l00075"></a>00075       
<a name="l00076"></a>00076    }
<a name="l00077"></a>00077    
<a name="l00084"></a><a class="code" href="class_j_shaft_panel.html#a3365657a97685d46d3acaaeadd6047aa">00084</a>    <span class="keyword">private</span> <span class="keyword">synchronized</span> <span class="keywordtype">void</span> <a class="code" href="class_j_shaft_panel.html#a3365657a97685d46d3acaaeadd6047aa" title="wechselt das Bild (image) auf das Benötigte aus und skaliert es bei bedarf">changePicture</a>(){
<a name="l00085"></a>00085       <span class="keywordtype">int</span> index;
<a name="l00086"></a>00086       <span class="keywordflow">if</span> (personenanz&gt;13){
<a name="l00087"></a>00087          index=14;
<a name="l00088"></a>00088       }<span class="keywordflow">else</span>{
<a name="l00089"></a>00089          index=personenanz;
<a name="l00090"></a>00090       }
<a name="l00091"></a>00091       currentimage = images[index].getScaledInstance(
<a name="l00092"></a>00092             -1,
<a name="l00093"></a>00093             getSize().height/9,
<a name="l00094"></a>00094             Image.SCALE_SMOOTH );
<a name="l00095"></a>00095       <span class="keywordflow">if</span>((<span class="keywordtype">int</span>)(243.0/342.7*(<span class="keywordtype">float</span>)(getSize().height/9))&gt;80){
<a name="l00096"></a>00096          
<a name="l00097"></a>00097          currentimage = images[index].getScaledInstance(
<a name="l00098"></a>00098             80,
<a name="l00099"></a>00099             -1,
<a name="l00100"></a>00100             Image.SCALE_SMOOTH );
<a name="l00101"></a>00101          System.out.println(<span class="stringliteral">&quot;HALLLOOOO&quot;</span>);
<a name="l00102"></a>00102       }
<a name="l00103"></a>00103    }
<a name="l00104"></a>00104    
<a name="l00113"></a><a class="code" href="class_j_shaft_panel.html#adb7e3c0157d8cbd2e68a25eb3882002d">00113</a>    <span class="keyword">public</span> <span class="keywordtype">void</span> <a class="code" href="class_j_shaft_panel.html#adb7e3c0157d8cbd2e68a25eb3882002d" title="Zeichnet die Tür in einer bestimmten Etage mit einem Bestimmten Grad an &quot;Öffnung&quot;.">drawDoors</a>(<span class="keywordtype">int</span> cond, <span class="keywordtype">int</span> floor){
<a name="l00114"></a>00114       floordoor=floor;
<a name="l00115"></a>00115       doorcond=cond;
<a name="l00116"></a>00116       repaint();
<a name="l00117"></a>00117    }
<a name="l00118"></a>00118    
<a name="l00127"></a><a class="code" href="class_j_shaft_panel.html#addf167511ca16e36dbbe362302aa4e01">00127</a>    <span class="keyword">public</span> <span class="keywordtype">void</span> <a class="code" href="class_j_shaft_panel.html#addf167511ca16e36dbbe362302aa4e01" title="Zeichnet den Lift in einer Bestimmten Etage mit einem Versatz.">drawLift</a>(<span class="keywordtype">int</span> pos, <span class="keywordtype">int</span> floor){
<a name="l00128"></a>00128       floordoor=floor;
<a name="l00129"></a>00129       liftpos=pos;
<a name="l00130"></a>00130       repaint();
<a name="l00131"></a>00131    }
<a name="l00132"></a>00132    
<a name="l00138"></a><a class="code" href="class_j_shaft_panel.html#a52fde6403def7032b219ffde0ab9efd4">00138</a>    <span class="keyword">public</span> <span class="keywordtype">void</span> <a class="code" href="class_j_shaft_panel.html#a52fde6403def7032b219ffde0ab9efd4" title="Über diese Methode wird die Zahl der Personen festgelegt, die im Fahrstuhl dargestellt werden...">setPersonen</a>(<span class="keywordtype">int</span> Personen){
<a name="l00139"></a>00139       <span class="keywordflow">if</span>(Personen!=personenanz){
<a name="l00140"></a>00140          personenanz=Personen;
<a name="l00141"></a>00141          changePicture();
<a name="l00142"></a>00142       }
<a name="l00143"></a>00143    }
<a name="l00144"></a>00144    
<a name="l00156"></a><a class="code" href="class_j_shaft_panel.html#a2920cb8927b61f0fc106774cf4366205">00156</a>    <span class="keyword">private</span> <span class="keyword">synchronized</span> <span class="keywordtype">void</span> <a class="code" href="class_j_shaft_panel.html#a2920cb8927b61f0fc106774cf4366205" title="Zeichnet die gesamte Grafik im Hintergrund (für double-Buffering)">offPaint</a>(){
<a name="l00157"></a>00157       
<a name="l00158"></a>00158        Dimension d = getSize();
<a name="l00159"></a>00159 
<a name="l00160"></a>00160        
<a name="l00161"></a>00161       offscreenImage    = createImage(d.width, d.height);
<a name="l00162"></a>00162       offscreenGraphics = offscreenImage.getGraphics();
<a name="l00163"></a>00163 
<a name="l00164"></a>00164       
<a name="l00165"></a>00165       Graphics2D g2 = (Graphics2D) offscreenGraphics; <span class="comment">//Aliasing</span>
<a name="l00166"></a>00166        <span class="keywordtype">int</span> heightoflevel=d.height/9;
<a name="l00167"></a>00167        <span class="comment">//Stockwerke</span>
<a name="l00168"></a>00168        <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i&lt;9; i++)
<a name="l00169"></a>00169        {
<a name="l00170"></a>00170          <span class="keywordflow">if</span>(i%2!=0){
<a name="l00171"></a>00171             g2.setPaint(Color.lightGray);
<a name="l00172"></a>00172             
<a name="l00173"></a>00173            }<span class="keywordflow">else</span>{
<a name="l00174"></a>00174             g2.setPaint(Color.white);
<a name="l00175"></a>00175            }
<a name="l00176"></a>00176          g2.fill(<span class="keyword">new</span> Rectangle2D.Double(0, i*heightoflevel, 200, heightoflevel));
<a name="l00177"></a>00177          g2.setPaint(Color.black);
<a name="l00178"></a>00178        }
<a name="l00179"></a>00179        <span class="comment">//Liftkabine</span>
<a name="l00180"></a>00180        <span class="keywordflow">if</span>(doorcond!=0 &amp;&amp; currentimage!=null ){
<a name="l00181"></a>00181           g2.setPaint(Color.white); <span class="comment">//Innenfarbe der Kabine</span>
<a name="l00182"></a>00182           g2.fill(<span class="keyword">new</span> Rectangle2D.Double(100-doorcond, (9-floordoor)*heightoflevel, 2*doorcond, heightoflevel)); <span class="comment">//Der Seitenrand beim Bild</span>
<a name="l00183"></a>00183           g2.drawImage(currentimage, 100-currentimage.getWidth(null)/2, (9-floordoor)*heightoflevel+((heightoflevel-currentimage.getHeight(null))/2), null);<span class="comment">//Das Bild</span>
<a name="l00184"></a>00184        }
<a name="l00185"></a>00185        g2.setPaint(Color.gray);
<a name="l00186"></a>00186        <span class="keywordflow">if</span>(doorcond!=0){
<a name="l00187"></a>00187          g2.fill(<span class="keyword">new</span> Rectangle2D.Double(60, (9-floordoor)*heightoflevel-(<span class="keywordtype">int</span>)((<span class="keywordtype">float</span>)heightoflevel*((<span class="keywordtype">float</span>)liftpos/40.0)), 40-doorcond, heightoflevel)); <span class="comment">//Linke Tür</span>
<a name="l00188"></a>00188          g2.fill(<span class="keyword">new</span> Rectangle2D.Double(100+doorcond, (9-floordoor)*heightoflevel-(<span class="keywordtype">int</span>)((<span class="keywordtype">float</span>)heightoflevel*((<span class="keywordtype">float</span>)liftpos/40.0)), 40-doorcond, heightoflevel)); <span class="comment">//Rechte Tür</span>
<a name="l00189"></a>00189        }<span class="keywordflow">else</span>
<a name="l00190"></a>00190          g2.fill(<span class="keyword">new</span> Rectangle2D.Double(60, (9-floordoor)*heightoflevel-(<span class="keywordtype">int</span>)((<span class="keywordtype">float</span>)heightoflevel*((<span class="keywordtype">float</span>)liftpos/40.0)), 80, heightoflevel)); <span class="comment">//Kabine</span>
<a name="l00191"></a>00191        g2.setPaint(Color.black);
<a name="l00192"></a>00192        
<a name="l00193"></a>00193       
<a name="l00194"></a>00194        
<a name="l00195"></a>00195        <span class="comment">//Etage</span>
<a name="l00196"></a>00196        <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0;i&lt;9; i++)
<a name="l00197"></a>00197        {          
<a name="l00198"></a>00198          g2.drawRect(60, i*heightoflevel, 80, heightoflevel);
<a name="l00199"></a>00199            <span class="keywordflow">if</span>((i!=(9-floordoor)) || (doorcond==0))
<a name="l00200"></a>00200                   g2.drawString(Integer.toString(9-i)+<span class="stringliteral">&quot;.Etage&quot;</span>, 75 , i*heightoflevel+20);
<a name="l00201"></a>00201        }          
<a name="l00202"></a>00202    }
<a name="l00203"></a>00203    
<a name="l00204"></a>00204    
<a name="l00205"></a>00205    
<a name="l00213"></a>00213    @Override 
<a name="l00214"></a><a class="code" href="class_j_shaft_panel.html#a9259b39f50f69772c077cc9fff837197">00214</a>    <span class="keyword">public</span> <span class="keywordtype">void</span> <a class="code" href="class_j_shaft_panel.html#a9259b39f50f69772c077cc9fff837197" title="Zeichnet den gesamten Schacht in das Panel.">paintComponent</a>(Graphics g) {
<a name="l00215"></a>00215       offPaint(); <span class="comment">//errechnet das, was dargestellt werden soll</span>
<a name="l00216"></a>00216       super.paintComponent(g);    <span class="comment">// paints background  </span>
<a name="l00217"></a>00217       <span class="keywordflow">if</span> ( offscreenImage != null ){
<a name="l00218"></a>00218          g.drawImage( offscreenImage, 0, 0, <span class="keyword">this</span> );
<a name="l00219"></a>00219          offscreenImage=null;
<a name="l00220"></a>00220       }<span class="keywordflow">else</span>
<a name="l00221"></a>00221          System.err.println(<span class="stringliteral">&quot;kein double-Buffering möglich=(&quot;</span>);
<a name="l00222"></a>00222     }
<a name="l00223"></a>00223 }
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Erzeugt am Fre Jul 6 2012 16:05:55 für LiftSimu von &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.0
</small></address>

</body>
</html>
